package com;

/**
 * 线程的yield()方法, 是放弃当前cpu资源给其他线程,但, 放弃的时间不确定, 会释放时间片, 不确定重新获取时间片的时间
 */
class Yield01 extends Thread {
    @Override
    public void run() {
        super.run();
        long beginTm = System.currentTimeMillis();
        int count = 0;
        for (int i = 0; i < 5000000; i++) {
            Thread.yield();
            count = (i + 1);
        }
        long endTm = System.currentTimeMillis();
        System.out.println("运行时间:" + (endTm - beginTm));
    }
}


public class Demo09 {
    public static void main(String[] args) {
        Yield01 thread = new Yield01();
        thread.setPriority(Thread.NORM_PRIORITY);
        thread.start();
    }
}
